﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="{$cfg_site_description}" />

<title>支付中心 - {$cfg_site_name}</title>
{template 'header'}
<body>
<div id="sysmsg-error-box" style="top:157px;display: none;">
	<div class="sysmsgw hidd" id="sysmsg-error" style="display: block;">
		<div class="sysmsg"><span>{$ERROR_MSG}</span><span class="close">關閉</span></div>
	</div>
	<div class="sysmsgw hidd" id="sysmsg-success" style="display: none;">
		<div class="sysmsg"><span></span><span class="close">關閉</span></div>
	</div>
</div>
<div id="buy917_wrap">  
    <div id="buy917_header">
    	<div id="buy917_logo"><a href="index.php">Buy917</a></div>
        <div class="buy917_header_banner">
        	<div class="buy917_header_topbanner">
				{template 'login_line'} <!-- login_line.html 登入/註冊按鈕 --> 
				<?php include("admin/event.php")?>
            </div>
          	<div class="buy917_header_select">
            	<div class="buy917_header_city">
                	 {if !empty($_cityid)}
                    <div class="guides">
                        <div class="city">
                            <h2>{$_cityname}</h2>
                        </div>
                        <div id="guides-city-change" class="change">切換城市</div>
                        <div id="guides-city-list" class="city-list">
                            <ul>
                            {loop $_citylist $v}
                                <li {if $v['cid']==$_cityid}class="current"{/if}><a href="index.php?cityid={$v['cid']}">{$v['cityname']}</a></li>
                            {/loop}
                            </ul>                   
                        </div>
                    </div>
                    {/if}	
                </div>
                <div class="buy917_header_group">
                	{template 'headergroup'}	
                </div>
            </div>
       </div>
    </div><!-- buy917_header -->
  
    {template 'menu_nav'} <!-- menu 導覽頁 --> 
       
    <div id="buy917_middle">
        	<div class="buy917_grouplist_top"></div>      
            <div class="buy917_grouplist_body"> 
               <h2>提交訂單</h2>
        		  <div id="content">
    <form action="ordercheck.php" method="get" id="deal-buy-form">
	<script>
	jQuery(function($){
		//初始化
		dealTotal();

		$("[id^=deal-buy-quantity-input]").keydown(function(event){		
		var event=event?event:window.event;
		var k=event.keyCode;
		
			
		if(!(k==8 || k==9 || k==13 || k==16 || k>=33 && k<=40 || k==45 || k==46 || k>=48 && k<=60 || k>=96 && k<=105))
		{
			return false;
		}
	}).blur(function(){
		var amountid = this.id;	
		var checkid = amountid.substr(-1,1);
		var amount=parseInt($('#' + amountid).val());		
				
		if(amount < 0)
		{
			$.showErr("購買數量不能小於0");
			$('#' + amountid).val(0);
			amount = 0;
		}
		else
		{
			$bln = false;
			$err = "";
			
			if(amount + userBuyCount > maxBought && maxBought > 0)
			{
				amount = maxBought - userBuyCount;
				
				$bln = true;
			}
			
			if(amount > surplusCount && goodsStock > 0)
			{
				amount = surplusCount;
				$bln = true;
			}
			
			
			
			if($bln)
			{
				if(maxBought > 0)
					$err+="每個用戶最可多購買"+maxBought+"單商品，";
				if(goodsStock > 0)
					$err+="現僅剩"+surplusCount+"單"+(($err == "") ? "商品" : "")+"，";
				$.showErr($err + "你已經購買了"+userBuyCount+"單，最多還能購買"+amount+"單。");
				
			}
			
			$('#' + amountid).val(amount);
		}
		
		var prices = Math.round(amount * goodsPrice * 100) /100;		
		if(prices != 0)
			prices = prices;
		else
			prices = 0;
			
			
		$('#deal-buy-total' + checkid).html(prices);		
		dealTotal()			
		
		
	});
	
	
	function dealTotal(){
	total = 0;
	$("[id^=deal-buy-total]").each(function(){
	if ($(this).html() != "")	total += parseInt($(this).html());
	})
	
		$('#t-deal-buy-total').html(total);
	}
	
	});
	</script>
	
	<script type="text/javascript">
var surplusCount = parseInt('{echo $value['stock']-$value['group_buynum']}');
var goodsStock = parseInt('0');
var goodsPrice = parseFloat('{$value[0]["shop_price"]}');
var maxBought = parseInt('{$value[0]["max_buynum"]}');
var userBuyCount = parseInt('{echo $userBuyCount?$userBuyCount:'0'}');
</script>

    <div id="deal-buy" class="box">
        <div class="box-top"></div>
        <div class="box-content">
           
            <div class="sect">
            <table width="90%" align="center" class="order-table">

                <tr>
                    <th bgcolor="#CCCCCC" class="deal-buy-desc" width="50%" >項目</th>
                    {if $v['subtitle']}<th bgcolor="#CCCCCC" class="deal-buy-desc" width="15%" >分店資訊</th>{/if}
                    <th bgcolor="#CCCCCC" class="deal-buy-quantity">數量</th>
                    <th colspan="2" bgcolor="#CCCCCC" class="deal-buy-multi">價格</th>
                    <th colspan="2" bgcolor="#CCCCCC" class="deal-buy-equal">總價</th>
                    
                  </tr>
					
                    <input type="hidden" name="gid" value="{$value[0]['gid']}">
                      {loop $value $v}
                      {if $v['title'] != ""}
                  		
                <tr>
                	<input type="hidden" name="gid{$v['id']}" value="{$v['gid']}">
                    <td class="deal-buy-desc">{mb_strimwidth($v['title'],0,200,'...','UTF-8')}</td>
					{if $v['subtitle']}<td class="deal-buy-desc">{$v['subtitle']}</td>{/if}
					{if 1>2}
	                    <td class="deal-buy-desc" align="center">{php $locals = (split(';',$v['local']))}
	                    <select name="locals">
	                    {php for($i=0;$i<sizeof($locals);$i++){ echo '<option value="'.$i.'">'.$locals[$i].'</option>'; }}
	                    </select>
	                    </td>
                    {/if}
                    <td class="deal-buy-quantity" align="right">
                    	<input type="text" class="input-text f-input" maxlength="4" size="5" name="quantity{$v['id']}" value="1" id="deal-buy-quantity-input{$v['id']}"/><br />
                    	<a id="deal-buy-update" href="javascript:void 0" style="display:none">更新數量</a></td>
                    <td class="deal-buy-multi">x</td>
                    <td align="center" class="deal-buy-price"><span class="money">$</span><span id="deal-buy-price">{$v['shop_price']}</span></td>
                    <td align="center" class="deal-buy-equal">=</td>
                    <td align="center" class="deal-buy-total">
                    	<span class="money">$</span><span id="deal-buy-total{$v['id']}">{$v['shop_price']}</span>
					</td>
                                      
   
                </tr>
                		{/if}
                {/loop}
                
                <tr id="cardcode-row" style="display:none;">
                    <td class="deal-buy-desc">禮品卡：<span id="cardcode-row-n"></span></td>
                    <td class="deal-buy-quantity"></td>
                    <td class="deal-buy-multi"></td>

                    <td class="deal-buy-price"></td>
                    <td align="center" class="deal-buy-equal"></td>
                    <td align="center" class="deal-buy-total">-<span class="money">$</span><span id="cardcode-row-t">0</span></td>
                </tr>
                                <tr class="order-total">
                    <td class="deal-buy-desc">&nbsp;</td>
                    <td class="deal-buy-quantity"></td>

                    <td class="deal-buy-multi"></td>
                    <td align="center" class="deal-buy-price"><span class="deal-buy-desc"><strong>應付總額</strong></span></td>
                    <td align="center" class="deal-buy-equal">=</td>
                    <td align="center" bgcolor="#F44D04" class="deal-buy-total"><span class="money"><font color="#FFFFFF">$</font></span><font color="#FFFFFF"><strong id="t-deal-buy-total">{$value['shop_price']}</strong></font></td>
                </tr>
            </table>
            <input id="deal-buy-cardcode" type="hidden" name="cardcode" maxlength="8" value="" />

            <input type="hidden" name="oid" value="{$oid}" />
                        <div class="form-submit"><div align="right" style="padding-right:45px; padding-top:20px;"><input type="submit" class="formbutton" name="buy" value="確認無誤，購買"/></div></div>
            </div>
        </div>
        <div class="box-bottom"></div>
    </div>
    </form>
</div>

			<!--<div class="cardcode">
                <h2>您有禮品卡嗎？</h2>
                <a href="javascript:void(0);" id="cardcode-link">點擊輸入禮品卡號碼</a>
                <p id="cardcode-link-t" class="act">
                    <input id="cardcode-text" class="f-input" type="text" name="cardcode" maxlength="8" value="" />
                    <input id="cardcode-deal" type="hidden" name="dealid" value="84" />

                    <input id="cardcode-verify" type="button" class="formbutton" value="確定" />
                </p>
            </div>-->

            </div><!-- buy917_grouplist_body -->
            <div class="buy917_grouplist_bottom"></div>
    </div><!-- buy917_middle -->
</div><!-- buy917wrap -->
<!-- footer -->
<script type="text/javascript">
jQuery(function($){
	$("#login-submit").click(function(){
		if($.trim($("#login-email-address").val()).length == 0)
		{
			$.showErr("請輸入您的帳號");
			$("#login-email-address").focus();
			return false;
		}
		if($.trim($("#login-password").val()).length == 0)
		{
			$.showErr("請輸入您的密碼");
			$("#login-email-address").focus();
			return false;
		}
	
	});
});
</script>
<div id="buy917_footer">
	{template 'footer'}	
</div>
</body>
</html>
<input type="hidden" text="<?php echo $_SESSION['refer'];?>">